
var initcatedatalink = webrootpath+"nlpner/initcatedatalink";  //加载分类树
var addcatedatalink = webrootpath+"nlpner/addcatedatalink";//添加ner分类内容
var deletecatedatabyidlink = webrootpath+"nlpner/deletecatedatabyidlink"; //根据id删除ner分类数据

var savedatalink = webrootpath+"data/savedata";
var cleardatalink = webrootpath+"data/cleardata";
var addtablink = webrootpath+"data/addtablink";
var deleteTaglink = webrootpath+"data/deleteTag";
var ner_delete_doclink = webrootpath+"data/ner_delete_doclink";//删除此内容

var deletetlink = webrootpath+"data/deletetlink";
var finddatalistlink = webrootpath+"data/finddatalist";
var findtagslistlink = webrootpath+"data/findtagslist";
var adddbcontentlink = webrootpath+"data/adddbcontent";

var upload_file = webrootpath+"file/upload_file"; //上传文件
var delAttached_link = webrootpath+"doc/delAttached_link"; //删除附件
var ner_modal_dialog_importdatalink = webrootpath+"data/ner_modal_dialog_importdatalink";//批量导入附件
var createBIODatalink = webrootpath+"data/createBIODatalink"; //生成BIO标注数据内容
var createdisBIODatalink = webrootpath+"data/createdisBIODatalink"; //生成BIO标注数据内容2


var selecttabstr = ""; //选中的文本
var zcdbid = ""; //获取本篇文章的id
var selpage = 1;


$(function () {
    findlmdata_link_fun(-1);

});
/***
 * 分类导航
 * @param _index
 */
function index_lm_tab(_index) {
    $("#index_lm_ul li").removeClass("active");
    $("#data_all_list").hide();
    $("#data_all_list_already_bj").hide();
    $("#all_div_center_right").hide();
    $("#data_all_list_bottom").hide();
    $("#data_list_gztdiv").hide();
    $("#dabaoshengcheng_div").hide();
    $("#tupujulei_div").hide();

    if (_index=="1"){
        $("#index_lm_ul li:eq(0)").addClass("active");
        $("#all_div_center_right").show();
        findtagslist();
    }else if(_index=="2"){
        $("#index_lm_ul li:eq(1)").addClass("active");
        $("#data_all_list").show();
        $("#data_all_list_bottom").show();
        $("#data_list_gztdiv").show();

        finddatalist(selpage);

        $("#data_all_list").mouseup(function (e) {
            var x = 10;
            var y = 10;
            var r = "";
            if (document.selection) {
                r = document.selection.createRange().text;
            }
            else if (window.getSelection()) {
                r = window.getSelection();

            }
            if (r!= "") {
                x = e.pageX;
                y = e.pageY;
                $("#tags_list_2").css({"margin-left":""+x+"px","margin-top":""+(y)+"px","width":"200px"});
                $("#tags_list_2").show();
                selecttabstr = r;
            }
        }).mousedown(function () {
            $("#tags_list_2").hide();
            selecttabstr=="";
        });

    }else if(_index=="3"){
        $("#index_lm_ul li:eq(2)").addClass("active");
        $("#data_all_list_already_bj").show();
        finddatalist(selpage);

    }else if(_index=="4"){
        $("#index_lm_ul li:eq(3)").addClass("active");
        $("#dabaoshengcheng_div").show();
        $("#ner_excel_id").prop("href","");
        $("#ner_excel_id").html("");
        $("#ner_txt_id").prop("href","");
        $("#ner_txt_id").html("");
    }else if(_index=="5"){
        $("#index_lm_ul li:eq(4)").addClass("active");
        $("#tupujulei_div").show();
        $("#tupujulei_div_content").load("./nlp_ner/zhishijulei.html");

    }
}

/****
 * 删除此文章
 */
function ner_delete_doc() {
    var r= window.confirm('您确定删除此内容吗？');
    if (r) {
        $.get(ner_delete_doclink,{zcdbid:zcdbid},function (msg) {
            alert(msg.msg);
            finddatalist((parseInt(selpage)-1));
            return false;
        });

    }
}
/***
 * 最大最小切换
 */
function index_nlp_nerzuidahua(_this){

    var boolbs = $(_this).text();
    if(boolbs=="最大化"){
        $(".index_div_2_1").hide();
        $("#index_nlp_nerfenleitree").hide();
        $("#index_div_2_2_id").css("width","100%");
        $("#index_nlp_nerfenleitree_content").css("width","99%");
        $(_this).text("最小化");

    }else{

        $(".index_div_2_1").show();
        $("#index_nlp_nerfenleitree").show();
        $("#index_div_2_2_id").css("width","84%");
        $("#index_nlp_nerfenleitree_content").css("width","84%");
        $(_this).text("最大化");


    }



}




/***
 * 生成BIO标注法预训练数据
 */
function createBIOData(){
    var r= window.confirm('您确定生成预训练文件吗？');
    if (r){
        $("#init_loading").modal("show");
        var treeObj = $.fn.zTree.getZTreeObj("index_lm_tree");
        var nodes = treeObj.getSelectedNodes();
        var selectcateid = nodes[0].cateid;
        $.get(createdisBIODatalink,{
            selectcateid:selectcateid
        },function (_info) {
            $("#init_loading").modal("hide");
            if(_info.code="1"){
                $("#ner_excel_id").prop("href",_info.data.csvpath);
                $("#ner_excel_id").html(_info.data.csvpath);
                $("#ner_txt_id").prop("href",_info.data.txtpath);
                $("#ner_txt_id").html(_info.data.txtpath);
                /*$("#regex_txt_id").prop("href",_info.data.regexpath);
                $("#regex_txt_id").html(_info.data.regexpath);*/


            }else{
                alert(_info.msg);
            }
        });
    }
}

/***
 * 批量导入数据
 */
function ner_modal_dialog_importdata() {
    var treeObj = $.fn.zTree.getZTreeObj("index_lm_tree");
    var nodes = treeObj.getSelectedNodes();
    var selectcateid = nodes[0].cateid;

    var att_name_list = "";
    $("input[name='att_name']").each(function (_index,_this) {
        att_name_list+=","+_this.value;
    });
    if(att_name_list==""){
        return false;
    }

    $("#init_loading").modal("show");

    $.post(ner_modal_dialog_importdatalink,{
        selectcateid:selectcateid,
        att_name_list:att_name_list
    },function (content) {
        $("#init_loading").modal("hide");
        if(content.code=="1"){
            $("#ner_modal_dialog").modal('hide');
            $.alert({content:content.msg});
            finddatalist(1);
            return false;
        }
    });



}
/***
 * 导入分类数据弹窗
 */
function importcatedatamodal() {

    $("#ner_modal_dialog").modal("show");
    setTimeout(function () {
        $("#ner_modal_dialog_picker").html("选择附件");
        loadnercateuploader();
    },500);

}

/***
 * 加载上传组件
 */
function loadnercateuploader() {
    $("#ner_modal_dialog_uploadlist").html("");
    $("#ner_modal_dialog_list").html("");

    var uploader = WebUploader.create({
        swf: './webuploader-0.1.5/Uploader.swf',
        auto:true,
        server: upload_file,
        pick: '#ner_modal_dialog_picker',
        resize: false,
        fileNumLimit:1,
        formData:{
            filetype:10
        },
        accept:{
            title: '压缩包',
            extensions: 'zip',
            mimeTypes: 'application/x-zip-compressed'
        },
        fileSizeLimit:10485760000
    });
    uploader.on( 'fileQueued', function( file ) {

        $("#ner_modal_dialog_uploadlist").html( '<div id="' + file.id + '" class="item">' +
            '<h4 class="info">' + file.name + '</h4>' +
            '<p class="state">等待上传...</p>' +
            '</div>' );
    });
    uploader.on( 'beforeFileQueued', function( file ) {
        uploader.reset();
    });

    uploader.on( 'uploadProgress', function( file, percentage ) {
        var $li = $( '#'+file.id ),
            $percent = $li.find('.progress .progress-bar');

        if ( !$percent.length ) {
            $percent = $('<div class="progress progress-striped active">' +
                '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                '</div>' +
                '</div>').appendTo( $li ).find('.progress-bar');
        }

        $li.find('p.state').text('上传中并正在处理，请稍等！！！');
        $percent.css( 'width', percentage * 100 + '%' );
    });
    //上传成功
    uploader.on( 'uploadSuccess', function( file,response ) {
        $( '#'+file.id ).find('p.state').text('上传完毕');

        setTimeout(function(){
            if(response.code=='1'){
                var htmlstr = "<tr id=\"att"+response.data.attachedid+"\" >"+
                    "<td>"+response.data.truename+"<input name='att_name' value='"+response.data.attachedid+"' style='display: none;' /></td>"+
                    "<td>"+response.data.size+"</td>"+
                    "<td><span class=\"label label-danger\" style='cursor: pointer;'  onclick=\"delAttached('"+response.data.attachedid+"')\">删除</span></td>"+
                    "</tr>";

                $("#ner_modal_dialog_list").append(htmlstr);
            }
            $("#ner_modal_dialog_uploadlist").html("");
            uploader.reset();
        },1000);

    });
    uploader.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错');
        uploader.reset();
    });
    uploader.on( 'uploadComplete', function( file ) {
        $( '#'+file.id ).find('.progress').fadeOut();
    });
}


/***
 *  删除附件
 */
function delAttached(attachedid) {
    $.confirm({
        title:"提示",
        content:"您确认删除此附件吗？",
        buttons:{
            "确定":function () {
                $.get(delAttached_link,{attachedid:attachedid},function (msg) {
                    if (msg.code=='1'){
                        $("#att"+attachedid).remove();
                        $.confirm({
                            title: '提示',
                            content: '成功删除附件！',
                            autoClose: '确定|2000',
                            buttons: {
                                确定: {
                                }
                            }
                        });
                    }
                });
            },
            "取消":function () {

            }
        }
    });
}






/***
 * 添加节点弹出窗口
 */
function index_lm_youjian_addnode() {
    index_lm_youjian_unb();
    $("#model_lm_nodename").val("");
    $("#model_lm_nodedesc").val("");
    $("#model_lm").modal('show');
}
/***
 * 添加节点提交更改
 */
function model_lm_model_submit() {
    var model_lm_nodename = $.trim($("#model_lm_nodename").val());
    var model_lm_nodedesc = $.trim($("#model_lm_nodedesc").val());
    var treeObj = $.fn.zTree.getZTreeObj("index_lm_tree");
    var nodes = treeObj.getSelectedNodes();
    $.post(addcatedatalink,{node_name:model_lm_nodename,node_desc:model_lm_nodedesc,selectlmid:nodes[0].cateid},function (data) {
        if (data.code=="1"){
            $("#model_lm").modal('hide');

            $.get(initcatedatalink,{node:data.data},function (data) {
                if (data.code=='1'){
                    var selecttreeobj = $.fn.zTree.getZTreeObj("index_lm_tree");
                    var nodes = selecttreeobj.getSelectedNodes();
                    selecttreeobj.removeChildNodes(nodes[0]);
                    selecttreeobj.addNodes(nodes[0], data.data.datalist);
                }
            });

        }
    });
}
/***
 * 删除分类节点
 */
function index_lm_youjian_deletenode() {
    var treeObj = $.fn.zTree.getZTreeObj("index_lm_tree");
    var nodes = treeObj.getSelectedNodes();
    var r=window.confirm("您确定删除此分类吗？");
    if (r==true){
        $.get(deletecatedatabyidlink,{lmid:nodes[0].cateid},function (msg) {
            if(msg.code=='1'){
                $.alert("删除成功");
                treeObj.removeNode(nodes[0]);
            }
        });
    }
}



/***
 * 获取词表分类数据
 */
function findlmdata_link_fun(_node) {
    var usertoken = sessionStorage.getItem("usertoken");


    $.get(initcatedatalink,{node:_node,usertoken:usertoken},function (data) {
        if (data.code=='1'){
            console.log(data.data);
            initTree(data.data);
        }
    });
}
/***
 * 初始化树结构
 */
function initTree(_treedata) {
    var zTreeObj;
    // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
    var setting = {
        data:{
            keep:{
                parent:true
            }
        },
        callback:{
            onRightClick:function (event, treeId, treeNode) {
                zTreeObj.selectNode(treeNode);
                var clientx = event.clientX-210;
                var clienty = event.clientY-50;

                $("#index_lm_youjian_cateid").html(treeNode.cateid);
                $("#index_lm_youjian").css({"margin-left":clientx,"margin-top":clienty,"display":"block"});

            },
            onExpand:function (event, treeId, treeNode) {

                var zAsync = treeNode.zAsync;
                //展开
                var treenodeid = treeNode.cateid;
                var usertoken = sessionStorage.getItem("usertoken");

                $.get(initcatedatalink,{node:treenodeid,usertoken:usertoken},function (data) {
                    if (data.code=='1'){
                        var sonnode = data.data.datalist;
                        zTreeObj.addNodes(treeNode, sonnode);
                    }
                });
            },
            onCollapse:function (event, treeId, treeNode) {
                //折叠后
                var treenodeid = treeNode.cateid;
                zTreeObj.removeChildNodes(treeNode);
            },
            onClick:function (event, treeId, treeNode,clickFlag) {
                //点击选择
                index_lm_tab(1);
            }
        }
    };
    // zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）
    zTreeObj = $.fn.zTree.init($("#index_lm_tree"), setting, _treedata.datalist);
    var nodes = zTreeObj.getNodes();
    if(nodes!=null && nodes!=""){
        zTreeObj.selectNode(nodes[0]);
        index_lm_tab(1);
    }





}
/***
 * 取消右键菜单
 */
function index_lm_youjian_unb() {
    $("#index_lm_youjian").css("display","none");
}
function index_lm_youjian_over() {
    $("#index_lm_youjian").css("display","block");
}


/******************************
 *  js分界线
 * @type {string}
 */


//保存
function baocun() {
    var r= window.confirm('您确定保存吗？');
    if (r){
        $.get(savedatalink,{zcdbid:zcdbid},function (msg) {
            alert(msg.msg);
            finddatalist(selpage);
            return false;
        });
    }
}
//清除标记
function qingchubiaoji() {
    var r= window.confirm('您确定清除标记吗？');
    if (r){
        $.get(cleardatalink,{zcdbid:zcdbid},function (msg) {
            alert(msg.msg);
            finddatalist(selpage);
            return false;
        });
    }
}

function shangyipian() {
    var yeval = $("#yematext").val();
    var yy = parseInt(yeval)-1;
    if(yy<=0){
        yy = 1;
    }
    finddatalist(yy);
}
function xiayipian() {
    var yeval = $("#yematext").val();
    var yy = parseInt(yeval)+1;
    if(yy<=0){
        yy = 1;
    }

    finddatalist(yy);

}
function tiaoye() {
    var yeval = $("#yematext").val();
    var yy = parseInt(yeval);
    if(yy<=0){
        yy = 1;
    }
    finddatalist(yy);
}

/***
 * 增加联系
 * @param _tid
 */
function funaddtablink(_tid,_tname) {

    if(selecttabstr==""){
        alert("没有获取选中数据");
        return false;
    }


    var sz_starttext = window.getSelection().anchorNode.data;
    var sz_startnum = window.getSelection().anchorOffset;
    var sz_endtext = window.getSelection().focusNode.data;
    var sz_endnum = window.getSelection().focusOffset;


    var scont = selecttabstr+"";
    $.ajax({
        type:"post",
        url:addtablink,
        data:{
            _tid:_tid,
            _tname:_tname,
            zcdbid:zcdbid,
            selecttabstr:scont,
            sz_starttext:sz_starttext,
            sz_startnum:sz_startnum,
            sz_endtext:sz_endtext,
            sz_endnum:sz_endnum
        },
        cache:false,
        async:true,
        success:function (msg) {
            $("#tags_list_2").hide();
            selecttabstr=="";
            alert(msg.msg);
            if(msg.code=="1"){
                /*var yeval = $("#yematext").val();
                var yy = parseInt(yeval);
                if(yy<=0){
                    yy = 1;
                }
                var data_all_listhtml = $("#data_all_list").html();
                var reg = new RegExp(selecttabstr, "g" )
                data_all_listhtml = data_all_listhtml.replace( reg ,"<font title='"+msg.tname+"' color='"+msg.tdesc+"'>"+selecttabstr+"</font>" );
                $("#data_all_list").html(data_all_listhtml);*/

                var zsdiccont = $("#data_all_list").html();
                var tname = msg.tname;
                var tdesc = msg.tdesc;
                var linkid = msg.linkid;
                var selecttabstr = scont;
                var alreadytag = "";


                if(sz_starttext==sz_endtext){
                    var sz_starttext_dispose = sz_starttext.slice(0,sz_startnum)+"<font title='"+tname+"'   style='background-color: "+tdesc+";padding: 5px;color: #ffffff;'>"+selecttabstr+"<font style='background-color: "+tdesc+";color: #ffffff;padding: 5px;line-height: 10px;cursor: pointer;' onclick='deleteTlink(this,\""+linkid+"\",1)'>&#10006;</font></font>"+sz_starttext.slice(sz_endnum);
                    zsdiccont = zsdiccont.replace(sz_starttext,sz_starttext_dispose);
                    alreadytag="<tr>" +
                        "<td>"+tname+"</td>" +
                        "<td>"+selecttabstr+"</td>" +
                        "<td><button type=\"button\" onclick='deleteTlink(this,\""+linkid+"\",2)' class=\"btn btn-danger\">删除</button></td>" +
                        "</tr>";
                }else {
                    var a_cont = sz_starttext.slice(0,sz_startnum)+"<font title='"+tname+"'   style='background-color: "+tdesc+";padding: 5px;color: #ffffff;'>"+selecttabstr;
                    var b_cont = "<font style='background-color: "+tdesc+";color: #ffffff;padding: 5px;line-height: 10px;cursor: pointer;'  onclick='deleteTlink(this,\""+linkid+"\",1)'>&#10006;</font></font>"+sz_endtext.slice(sz_endnum);
                    zsdiccont = zsdiccont.replace(sz_starttext,a_cont);
                    zsdiccont = zsdiccont.replace(sz_endtext,b_cont);


                    alreadytag="<tr>" +
                        "<td>"+tname+"</td>" +
                        "<td>"+selecttabstr+"</td>" +
                        "<td><button type=\"button\" onclick='deleteTlink(this,\""+linkid+"\",2)' class=\"btn btn-danger\">删除</button></td>" +
                        "</tr>";
                }

                $("#data_all_list").html(zsdiccont);
                $("#data_all_list_yuanwen").append(alreadytag);


            }
        },
        error:function (msg) {
            alert(msg);
        }
    });
    return false;
}

/***
 * 删除标签
 * @param _tid
 */
function deleteTag(_tid) {
    var r= window.confirm('您确定删除标签吗');
    if (r){
        $.get(deleteTaglink,{tid:_tid},function (msg) {
            alert(msg.msg);
            findtagslist();
        });
    }
}

/**
 * 删除标签文章联系根据联系id
 * @param _tlinkid
 */
function deleteTlink(_this,_tlinkid,_type) {



    var r= window.confirm('您确定删除此标记吗？');
    if (r){
        $.get(deletetlink,{tlinkid:_tlinkid},function (msg) {
            //alert(msg.msg);
            if(_type==1){

                var seltextstr = $(_this).parent().text();
                var outerhtmlstr = $(_this).parent()[0].outerHTML;
                var zhtml = $("#data_all_list").html();
                seltextstr = seltextstr.replace("&#10006;","");
                seltextstr = seltextstr.replace("✖","");
                zhtml = zhtml.replace(outerhtmlstr,seltextstr);
                $("#data_all_list").html(zhtml);
            }else {
                finddatalist(selpage);



            }



        });
    }
}
/***
 * 获取主数据列表
 */
function finddatalist(_page) {

    document.getElementById("data_all_list").scrollTop = 0;
    var treeObj = $.fn.zTree.getZTreeObj("index_lm_tree");
    var nodes = treeObj.getSelectedNodes();
    var selectcateid = nodes[0].cateid;


    $.ajax({
        type:"post",
        url:finddatalistlink,
        data:{
            selectcateid:selectcateid,
            zctype:10,
            pagenum:_page
        },
        cache:false,
        async:false,
        success:function (msg) {
            selpage = _page;
            if (msg.code=="1"){
                var dataobj = msg.data.dataobj;
                var zcstatusval = "";
                if(dataobj.zcstatus=="10"){
                    zcstatusval = "正在标记";
                }else if (dataobj.zcstatus=="20"){
                    zcstatusval = "其他人正在标记";
                }else if (dataobj.zcstatus=="30"){
                    zcstatusval = "完成标记，共";
                }
                zcdbid = dataobj.zcid;
                $("#data_title").html("名称："+dataobj.zcname+"&nbsp;&nbsp;&nbsp;&nbsp;状态："+zcstatusval);
                //$("#data_all_list").html(dataobj.zcdiscontent);
                $("#data_all_list_font").html("当前进度：<input id='yematext' type='text' style='height: 20px;width: 40px;' value='"+msg.data.pagenum+"' />&nbsp;/&nbsp;"+msg.data.pagesize+"&nbsp;&nbsp;<a style='cursor: pointer;' href='javascript:void(0);' onclick='tiaoye()'>跳页</a>");

                setTimeout(function () {
                    var taglist = msg.data.taglist;
                    if(taglist.length>0){
                        $("#data_title").html("名称："+dataobj.zcname+"&nbsp;&nbsp;&nbsp;&nbsp;状态："+zcstatusval+taglist.length+"次");
                    }

                    var alreadytag = "";
                    var zsdiccont = dataobj.zcdiscontent;
                    for(var i in taglist){
                        var tgi = taglist[i];
                        var tname = tgi.tname;
                        var tdesc = tgi.tdesc;
                        var tdatacontent = tgi.datacontent;
                        var datacontentisjson = tgi.datacontentisjson;


                        if(datacontentisjson==true){
                            var tdatacontentarray = JSON.parse(tdatacontent);
                            var selecttabstr = tdatacontentarray.selecttabstr;
                            var sz_starttext = tdatacontentarray.sz_starttext;
                            var sz_startnum = tdatacontentarray.sz_startnum;
                            var sz_endtext = tdatacontentarray.sz_endtext;
                            var sz_endnum = tdatacontentarray.sz_endnum;

                            if(sz_starttext==sz_endtext){
                                var sz_starttext_dispose = sz_starttext.slice(0,sz_startnum)+"<font title='"+tname+"'   style='background-color: "+tdesc+";padding: 5px;color: #ffffff;'>"+selecttabstr+"<font style='background-color: "+tdesc+";color: #ffffff;padding: 5px;line-height: 10px;cursor: pointer;' onclick='deleteTlink(this,\""+tgi.tlinkid+"\",1)'>&#10006;</font></font>"+sz_starttext.slice(sz_endnum);
                                zsdiccont = zsdiccont.replace(sz_starttext,sz_starttext_dispose);
                                alreadytag+="<tr>" +
                                    "<td>"+tname+"</td>" +
                                    "<td>"+selecttabstr+"</td>" +
                                    "<td><button type=\"button\" onclick='deleteTlink(this,\""+tgi.tlinkid+"\",2)' class=\"btn btn-danger\">删除</button></td>" +
                                    "</tr>";
                            }else {
                                var a_cont = sz_starttext.slice(0,sz_startnum)+"<font title='"+tname+"'   style='background-color: "+tdesc+";padding: 5px;color: #ffffff;'>"+selecttabstr;
                                var b_cont = "<font style='background-color: "+tdesc+";color: #ffffff;padding: 5px;line-height: 10px;cursor: pointer;' onclick='deleteTlink(this,\""+tgi.tlinkid+"\",1)'>&#10006;</font></font>"+sz_endtext.slice(sz_endnum);
                                zsdiccont = zsdiccont.replace(sz_starttext,a_cont);
                                zsdiccont = zsdiccont.replace(sz_endtext,b_cont);


                                alreadytag+="<tr>" +
                                    "<td>"+tname+"</td>" +
                                    "<td>"+selecttabstr+"</td>" +
                                    "<td><button type=\"button\" onclick='deleteTlink(this,\""+tgi.tlinkid+"\",2)' class=\"btn btn-danger\">删除</button></td>" +
                                    "</tr>";
                            }
                        }else{
                            zsdiccont = zsdiccont.replace(tdatacontent,"<font title='"+tname+"'   style='background-color: "+tdesc+";padding: 5px;color: #ffffff;'>"+tdatacontent+"<font style='background-color: "+tdesc+";color: #ffffff;padding: 5px;line-height: 10px;cursor: pointer;' onclick='deleteTlink(this,\""+tgi.tlinkid+"\",1)'>&#10006;</font></font>");
                            alreadytag+="<tr>" +
                                "<td>"+tname+"</td>" +
                                "<td>"+tdatacontent+"</td>" +
                                "<td><button type=\"button\" onclick='deleteTlink(this,\""+tgi.tlinkid+"\",2)' class=\"btn btn-danger\">删除</button></td>" +
                                "</tr>";
                        }


                    }

                    $("#data_all_list").html(zsdiccont);
                    $("#data_all_list_yuanwen").html(dataobj.zccontent);

                    $("#data_all_list_already_bj_tbody").html(alreadytag);
                },100)


            }
        },
        error:function (msg) {
            console.log(msg);
        }
    });
}
/***
 * 获取标签列表
 */
function findtagslist() {
    $("#tags_list").html("");
    $("#tags_list_2").html("");
    var treeObj = $.fn.zTree.getZTreeObj("index_lm_tree");
    var nodes = treeObj.getSelectedNodes();
    var selectcateid = nodes[0].cateid;

    $.ajax({
        type:"post",
        url:findtagslistlink,
        data:{
            tag_leibie:selectcateid
        },
        cache:false,
        async:false,
        success:function (msg) {
            if(msg.code==1){
                var datalist = msg.data.datalist;
                var datahtmlstr = "";
                var selecthmlstr = "";
                for(var i in datalist){
                    var dataobj = datalist[i];
                    datahtmlstr+="<tr>" +
                        "<td>"+(parseInt(i)+1)+"</td>" +
                        "<td>"+dataobj.tname+"</td>" +
                        "<td>"+dataobj.tnamedesc+"</td>" +
                        "<td><label style='width: 100px;height: 20px;background-color: "+dataobj.tdesc+";' title='"+dataobj.tdesc+"'></label></td>" +
                        "<td>"+timestampToTime(dataobj.crdate)+"</td>" +
                        "<td><button class=\"btn btn-danger\" onclick='deleteTag(\""+dataobj.tid+"\")' >删除</button></td>" +
                        "</tr>";

                    selecthmlstr += "<li class='list-group-item' title='"+dataobj.tdesc+"'><a href='javascript:void(0);' onclick='funaddtablink(\""+dataobj.tid+"\",\""+dataobj.tname+"\")'>"+dataobj.tname+"</a></li>";
                }
                $("#tags_list").html(datahtmlstr);
                $("#tags_list_2").html(selecthmlstr);

            }else {
                //alert("获取标签列表失败");
            }
        },
        error:function (msg) {
            alert("网络连接错误");
        }
    });
}




/***
 * 添加标签
 */
function addtagsclick(){
    $("#addtags_model").modal("show");
    $("#tag_name").val("");
    $("#tag_namedesc").val("");
}
function addtags_model_submitclick() {
    var treeObj = $.fn.zTree.getZTreeObj("index_lm_tree");
    var nodes = treeObj.getSelectedNodes();
    var selectcateid = nodes[0].cateid;

    var tag_name = $.trim($("#tag_name").val());
    var tag_namedesc = $.trim($("#tag_namedesc").val());
    var tag_desc = $.trim($("#tag_desc").val());

    if(tag_name==""){
        alert("请填写标签名称");
        return false;
    }
    $.ajax({
        type:"post",
        url:adddbcontentlink,
        data:{
            tag_name:tag_name,
            tag_namedesc:tag_namedesc,
            tag_desc:tag_desc,
            tag_leibie:selectcateid
        },
        cache:false,
        async:true,
        success:function (msg) {
            $("#addtags_model").modal("hide");
            findtagslist();
            alert(msg.msg);
        },
        error:function (msg) {
            alert(msg);
        }
    });
}
